#pragma once
#include<iostream>
#include <sys/epoll.h>
#include<unistd.h>
class Epoll
{
    static const int size = 128;
public:
    Epoll()
    {
        epfd_ = epoll_create(size);
        if(epfd_ == -1)
        {
            std::cout<<"epoll create error"<<std::endl;
        }
        else
        {
            std::cout<<"epoll create success"<<std::endl;

        }
    }
    int EpollWait(struct epoll_event revents[],int num)
    {
        int n = epoll_wait(epfd_,revents,num,timeout_);
        return n;
    }
    int EpollUpdate(int oper,int sock,uint32_t event)
    {
        int n = 0;
        if(oper == EPOLL_CTL_DEL)
        {
            n = epoll_ctl(epfd_,oper,sock,nullptr);
            if(n != 0)
            {
                std::cout<<"epoll_ctl error"<<std::endl;
            }
        }
        else
        {
            struct epoll_event ev;
            ev.events = event;
            ev.data.fd = sock;
            n = epoll_ctl(epfd_,oper,sock,&ev);
            if(n != 0)
            {
                std::cout<<"epoll_ctr error"<<std::endl;
            }
        }
        return n;
    }
    ~Epoll()
    {
        if(epfd_ > 0)
        {
            close(epfd_);
        }
    }

private:
    int epfd_;
    int timeout_{3000};
};